package genetic.q4.v2;
import java.util.LinkedList;
import java.util.List;

import genetic.Genotype;
import genetic.q4.EternityPiece;

public class EternityGenotype implements Genotype{

	List<EternityPiece> frame;
	List<EternityPiece> innerFrame;
	public EternityGenotype(List<EternityPiece> f1, List<EternityPiece> f2) {
		this.frame = f1;
		this.innerFrame = f2;
	}

	@Override
	public int[] getIntString() {
		return null;
	}

	@Override
	public Genotype clone() {
		List<EternityPiece> newList = new LinkedList<EternityPiece>(frame);
		List<EternityPiece> newList2 = new LinkedList<EternityPiece>(innerFrame);
		return new EternityGenotype(newList, newList2);
	}

	public double getSize() {
		return frame.size() + innerFrame.size();
	}
	
	public double getOuterSize() {
		return frame.size();
	}
	
	public double getInnerSize() {
		return innerFrame.size();
	}

	public EternityPiece getPiece(int id, int i) {
		if (id==0){ 
			return frame.get(i);
		}
		else return innerFrame.get(i);
	}

	public int indexOfOuter(EternityPiece eternityPiece) {
		return frame.indexOf(eternityPiece);
	}
	public int indexOfInner(EternityPiece eternityPiece) {
		return innerFrame.indexOf(eternityPiece);
	}
	
	@Override
	public String toString() {
		return getSize() + " - " + frame.toString() + " - " + innerFrame.toString();
	}

	public double getFitness() {
		if (frame.size()<60) return frame.size();
		if (frame.get(0).getColor(EternityPiece.GRAY, 1, EternityPiece.GRAY, 3) == frame.get(59).getColor(EternityPiece.GRAY, 1)){
			if (innerFrame.size()<52){
				return 61 + innerFrame.size()*2;
			}
			int p1color = frame.get(1).getColor(EternityPiece.GRAY, 2);
			int p2color = frame.get(59).getColor(EternityPiece.GRAY, 2);
			int p3color = frame.get(58).getColor(EternityPiece.GRAY, 2);
			int color = innerFrame.get(0).getColor(p1color, 1, p2color, 3);
			if (frame.get(51).fits(p3color, 1, color)){
				return  61+52*2+2;
			}
			return 61+52*2;
			
			
		}
		return 60;
	}


}
